import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',// alwaysShow: true,
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard', affix: true }
    }]
  },
  {
    path: '/sale-manage',
    component: Layout,
    redirect: '/sale-manage/sale-order',
    name: 'SaleManage',
    meta: { title: '销售管理',icon: 'user'},
    children: [
      {
        path: 'sale-order',
        name: 'SaleOrder',
        component: () => import('@/views/sale-manage/sale-order/index'),
        meta: { title: '新增销售订单' }
      },
      // {
      //   path: 'open-order',
      //   name: 'OpenOrder',
      //   component: () => import('@/views/sale-manage/open-order/index'),
      //   meta: { title: '未处理订单' }
      // },
      // {
      //   path: 'return-order',
      //   name: 'ReturnOrder',
      //   component: () => import('@/views/sale-manage/return-order/index'),
      //   meta: { title: '退回订单' }
      // },
      {
        path: 'after-sales',
        name: 'AfterSales',
        component: () => import('@/views/sale-manage/after-sales/index'),
        meta: { title: '售后管理' }
      },
      { //自己加的
        path: 'sales-record',
        name: 'SalesRecord',
        component: () => import('@/views/sale-manage/sales-record/index'),
        meta: { title: '销售单记录' }
      }
    ]
  },
  {
    path: '/stock-manage',
    component: Layout,
    redirect: '/stock-manage/purchasing-system',
    name: 'StockManage',
    meta: { title: '库存管理',icon: 'user'},
    children: [
      {
        path: 'purchasing-system',
        name: 'PurchasingSystem',
        component: () => import('@/views/stock-manage/purchasing-system/index'),
        meta: { title: '采购入库' }
      },
      {
        path: 'purchasing-list',
        name: 'PurchasingList',
        component: () => import('@/views/stock-manage/purchasing-list/index'),
        meta: { title: '购货单列表' }
      },
      {
        path: 'stock-taking',
        name: 'StockTaking',
        component: () => import('@/views/stock-manage/stock-taking/index'),
        meta: { title: '库存盘点' }
      },
      {
        path: 'stock-allot',
        name: 'StockAllot',
        component: () => import('@/views/stock-manage/stock-allot/index'),
        meta: { title: '库存调拨' }
      },
      {
        path: 'loss-list',
        name: 'LossList',
        component: () => import('@/views/stock-manage/loss-list/index'),
        meta: { title: '损耗列表' }
      },
      {
        path: 'warehouse-manage',
        name: 'WarehouseManage',
        component: () => import('@/views/stock-manage/warehouse-manage/index'),
        meta: { title: '仓库管理' }
      }
    ]
  },
  {
    path: '/supplier-manage',
    component: Layout,
    redirect: '/supplier-manage/supplier-sort',
    name: 'SupplierManage',
    meta: { title: '供货商管理',icon: 'user'},
    children: [
      {
        path: 'supplier-sort',
        name: 'SupplierSort',
        component: () => import('@/views/supplier-manage/supplier-sort/index'),
        meta: { title: '供货商分类' }
      },
      {
        path: 'supplier-list',
        name: 'SupplierList',
        component: () => import('@/views/supplier-manage/supplier-list/index'),
        meta: { title: '供货商列表' }
      },
      {
        path: 'capital',
        name: 'Capital',
        component: () => import('@/views/supplier-manage/capital/index'),
        meta: { title: '资金流水' }
      }
    ]
  },
  {
    path: '/agent-manage',
    component: Layout,
    redirect: '/agent-manage/agent-level',
    name: 'AgentManage',
    meta: { title: '代理商管理',icon: 'user'},
    children: [
      {
        path: 'agent-level',
        name: 'AgentLevel',
        component: () => import('@/views/agent-manage/agent-level/index'),
        meta: { title: '代理商等级' }
      },
      {
        path: 'agent-list',
        name: 'AgentList',
        component: () => import('@/views/agent-manage/agent-list/index'),
        meta: { title: '代理商列表' }
      }
    ]
  },
  {
    path: '/goods-manage',
    component: Layout,
    redirect: '/goods-manage/goods-list',
    name: 'GoodsManage',
    alwaysShow: true, //展示
    meta: { title: '商品管理',icon: 'user'},
    children: [
      {
        path: 'goods-sort',
        name: 'GoodsSort',
        component: () => import('@/views/goods-manage/goods-sort/index'),
        meta: { title: '商品分类' }
      },
      {
        path: 'goods-list',
        name: 'GoodsList',
        component: () => import('@/views/goods-manage/goods-list/index'),
        meta: { title: '商品列表' }
      },
      {
        path: 'goods-model',
        name: 'GoodsModel',
        component: () => import('@/views/goods-manage/goods-model/index'),
        meta: { title: '商品规格' }
      }
    ]
  },
  {
    path: '/pack-manage',
    component: Layout,
    redirect: '/pack-manage/pack-sort',
    name: 'PackManage',
    meta: { title: '包装管理',icon: 'user'},
    children: [
      {
        path: 'pack-sort',
        name: 'PackSort',
        component: () => import('@/views/pack-manage/pack-sort/index'),
        meta: { title: '包装分类' }
      },
      {
        path: 'pack-list',
        name: 'PackList',
        component: () => import('@/views/pack-manage/pack-list/index'),
        meta: { title: '包装列表' }
      }
    ]
  },
  {
    path: '/finance-manage',
    component: Layout,
    redirect: '/finance-manage/to-audit',
    name: 'FinanceManage',
    alwaysShow: true,
    meta: { title: '财务管理',icon: 'user'},
    children: [
      {
        path: 'to-audit',
        name: 'ToAudit',
        component: () => import('@/views/finance-manage/to-audit/index'),
        meta: { title: '待审核订单' }
      },
      {
        path: 'audited',
        name: 'Audited',
        component: () => import('@/views/finance-manage/audited/index'),
        meta: { title: '已审核订单' }
      },
      {
        path: 'ar',
        name: 'AR',
        component: () => import('@/views/finance-manage/ar/index'),
        meta: { title: '应收管理' }
      },
      {
        path: 'ap',
        name: 'AP',
        component: () => import('@/views/finance-manage/ap/index'),
        meta: { title: '应付管理' }
      },
      {
        path: 'finance-details',
        name: 'FinanceDetails',
        component: () => import('@/views/finance-manage/finance-details/index'),
        meta: { title: '财务明细' }
      }
    ]
  },
  {
    path: '/data-statistics',
    component: Layout,
    redirect: '/data-statistics/merchant-statement',
    name: 'DataStatistics',
    alwaysShow: true,
    meta: { title: '数据统计',icon: 'user'},
    children: [
      {
        path: 'sales-report',
        name: 'SalesReport',
        component: () => import('@/views/data-statistics/sales-report/index'),
        meta: { title: '销售报表' }
      },
      {
        path: 'purchase-report',
        name: 'PurchaseReport',
        component: () => import('@/views/data-statistics/purchase-report/index'),
        meta: { title: '采购报表' }
      },
      {
        path: 'warehouse-report',
        name: 'WarehouseReport',
        component: () => import('@/views/data-statistics/warehouse-report/index'),
        meta: { title: '仓储报表' }
      },
      {
        path: 'store-sale-report',
        name: 'StoreSaleReport',
        component: () => import('@/views/data-statistics/store-sale-report/index'),
        meta: { title: '门店销售报表' }
      },
      {
        path: 'finance-report',
        name: 'FinanceReport',
        component: () => import('@/views/data-statistics/finance-report/index'),
        meta: { title: '财务报表' }
      }
    ]
  },
  {
    path: '/system-manage',
    component: Layout,
    redirect: '/system-manage/user-manage',
    name: 'SystemManage',
    meta: { title: '系统管理',icon: 'user'},
    children: [
      {
        path: 'user-manage',
        name: 'UserManage',
        component: () => import('@/views/system-manage/user-manage/index'),
        meta: { title: '用户管理' }
      },
      {
        path: 'role-manage',
        name: 'RoleManage',
        component: () => import('@/views/system-manage/role-manage/index'),
        meta: { title: '角色管理' }
      },
      {
        path: 'access-rule',
        name: 'AccessRule',
        component: () => import('@/views/system-manage/access-rule/index'),
        meta: { title: '权限规则' }
      },
      {
        path: 'set-manage',
        name: 'SetManage',
        component: () => import('@/views/system-manage/set-manage/index'),
        meta: { title: '系统设置' }
      },
      {
        path: 'edit-log',
        name: 'EditLog',
        component: () => import('@/views/system-manage/edit-log/index'),
        meta: { title: '操作日志' }
      },
      {
        path: 'safety-center',
        name: 'SafetyCenter',
        component: () => import('@/views/system-manage/safety-center/index'),
        meta: { title: '安全中心' }
      }
    ]
  },
  // {
  //   path: '/notification',
  //   component: Layout,
  //   redirect: '/notification/understock',
  //   name: 'Notification',
  //   meta: { title: '消息提醒',icon: 'user'},
  //   children: [
  //     {
  //       path: 'understock',
  //       name: 'Understock',
  //       component: () => import('@/views/notification/understock/index'),
  //       meta: { title: '库存不足预警' }
  //     },
  //     {
  //       path: 'stock-net',
  //       name: 'stockNet',
  //       component: () => import('@/views/notification/stock-net/index'),
  //       meta: { title: '库存进销问题预警' }
  //     },
  //     {
  //       path: 'order-remind',
  //       name: 'OrderRemind',
  //       component: () => import('@/views/notification/order-remind/index'),
  //       meta: { title: '新订单提醒' }
  //     },
  //     {
  //       path: 'shipment-remind',
  //       name: 'ShipmentRemind',
  //       component: () => import('@/views/notification/shipment-remind/index'),
  //       meta: { title: '发货提醒' }
  //     }
  //   ]
  // },
  {
    path: '/store-manage',
    component: Layout,
    redirect: '/store-manage/store-sort',
    name: 'StoreManage',
    meta: { title: '门店管理',icon: 'user'},
    children: [
      {
        path: 'store-sort',
        name: 'StoreSort',
        component: () => import('@/views/store-manage/store-sort/index'),
        meta: { title: '门店分类' }
      },
      {
        path: 'store-list',
        name: 'StoreList',
        component: () => import('@/views/store-manage/store-list/index'),
        meta: { title: '门店列表' }
      }
    ]
  },
  { //自己加的
    path: '/client-manage',
    component: Layout,
    redirect: '/client-manage/client-sort',
    name: 'ClientManage',
    meta: { title: '客户管理',icon: 'user'},
    children: [
      {
        path: 'client-sort',
        name: 'ClientSort',
        component: () => import('@/views/client-manage/client-sort/index'),
        meta: { title: '客户分类' }
      },
      {
        path: 'client-list',
        name: 'ClientList',
        component: () => import('@/views/client-manage/client-list/index'),
        meta: { title: '客户列表' }
      }
    ]
  },
  {
    path: '/logistics',
    component: Layout,
    redirect: '/logistics-manage/express',
    name: 'Logistics',
    meta: { title: '物流设置',icon: 'user'},
    children: [
      {
        path: 'express',
        name: 'Express',
        component: () => import('@/views/logistics/express/index'),
        meta: { title: '物流公司' }
      },
      {
        path: 'configure',
        name: 'Configure',
        component: () => import('@/views/logistics/configure/index'),
        meta: { title: '物流配置' }
      },
      {
        path: 'city-data',
        name: 'CityData',
        component: () => import('@/views/logistics/city-data/index'),
        meta: { title: '城市数据' }
      },
      {
        path: 'freight-temp',
        name: 'FreightTemp',
        component: () => import('@/views/logistics/freight-temp/index'),
        meta: { title: '运费模板' }
      }
    ]
  }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [



  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
